package com.app;

import java.security.Principal;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;

public class LoggingUtil {

	private static final Logger LOG = Logger.getLogger("AUDIT");
	public static final String OPERATION_UPDATE = "updated";
	public static final String OPERATION_CREATE = "created";
	public static final String OPERATION_DELETE = "deleted";

	public static void logOperation(String operation, Object entity) {
		if (LOG.isLoggable(Level.INFO)) {
			ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
			Principal userPrincipal = externalContext.getUserPrincipal();
			if (userPrincipal != null) {
				LOG.info("User '" + userPrincipal.getName() + "' " + operation + " " + entity);
			}
		}
	}

}
